<?php

namespace System\Database;

if (!defined('BASEPATH')) die('Access Denied.');

/**
 * 
 * µMVC Framework (c) 2011.
 * 
 * PHP5 MVC Framework software for PHP 5.2.17 or later
 * 
 * Database adapted from Obullo framework based on work from CodeIgniter
 * 
 * @package         µMVC
 * @filename        system/database/dbresults.class.php
 * @copyright       Lanz (c) 2011.
 * 
 * @author          Ersin Güvenç
 * 
 */

use \PDO as PDO;
use \PDOStatement as PDOStatement;

/**
 * DB class
 * 
 * @package         µMVC
 * @subpackage      Database
 * @category        System
 */
class DBException extends \System\Core\CommonException {}

/**
 * DBResults Class
 *
 * Fetch DB Results.
 *
 * @package         Obullo 
 * @subpackage      Base.database     
 * @category        Database
 * @version         0.1
 */
// predefined db constants
define('assoc', 'assoc');
define('obj', 'obj');
define('bound', 'bound');
define('col', 'col');
define('num', 'num');

// paramater types
define('p_int', 'int');
define('p_str', 'str');
define('p_bool', 'bool');
define('p_null', 'null');

// active record pdo secure like constant 
define('p_like', 'like');

Class DBResults
{

    // Factory fetch type
    public static function fetch($type='')
    {
        switch ($type)
        {
            case 'assoc':
                return PDO::FETCH_ASSOC;
                break;

            case 'obj':
                return PDO::FETCH_OBJ;
                break;

            //get column names and column nubers togetger
            case 'bound':
                return PDO::FETCH_BOUND;
                break;

            //get just column info
            case 'col':
                return PDO::FETCH_COLUMN;
                break;

            case 'num':
                return PDO::FETCH_NUM;
                break;

            default:
                return PDO::FETCH_ASSOC;
        }
    }

//end fecth.

    public static function type($type='')
    {
        switch ($type)
        {
            // integer
            case 'int':
                return PDO::PARAM_INT;
                break;

            // string
            case 'str':
                return PDO::PARAM_STR;
                break;

            // boolean
            case 'bool':
                return PDO::PARAM_BOOL;
                break;

            default:
                return PDO::PARAM_STR;
        }
    }

}

//end class.
?>
